#演示字典常用操作

my_dict =   {"周杰伦":99,"林俊杰":88,"张学友":77}

#新增元素
my_dict["张信哲"] =66
print(f"字典新增元素后，结果为：{my_dict}")
#更新元素  赋值
my_dict["周杰伦"]=33
print(f"字典更新元素后，结果为：{my_dict}")

#删除元素 pop
score = my_dict.pop("周杰伦")
print(f"字典删除元素后，结果为：{my_dict}，周杰伦的分数为：{score}")

#清空元素 clear
my_dict.clear()
type1 = type(my_dict)
print(f"字典清空元素后，结果为：{my_dict}，类型为：{type1}")

#获取全部key值
my_dict =   {"周杰伦":99,"林俊杰":88,"张学友":77}
keys = my_dict.keys()
print(f"字典的全部key值为：{keys}")

# 遍历字典
#  方式一：
for key in keys:
    print(f"字典的key值为:{key}")
    print(f"字典的value是：{my_dict[key]}")
print (f"***************************")

# 方法二
for key in my_dict:
    print(f"字典的key值为:{key}")
    print(f"字典的value是：{my_dict[key]}")

#统计字典内的元素数量
num = len(my_dict)
print(f"字典内的元素个数:{num}")


#练习题：升职加薪
employee_dict = {"王力宏":{"部门":"科技部","工资":3000,"级别":1},"周杰伦":{"部门":"市场部","工资":5000,"级别":2},
"林俊杰":{"部门":"市场部","工资":7000,"级别":3},"张学友":{"部门":"科技部","工资":4000,"级别":1},"刘德华":{"部门":"市场部","工资":6000,"级别":2}}
for name in employee_dict:
    if employee_dict[name]["级别"] == 1:
    #升职加薪
        e_dict = employee_dict[name]
        e_dict["级别"] = 2 #级别加1
        e_dict["工资"] += 1000  #工资加1000
        employee_dict[name] = e_dict
    #输出结果
print(f"对员工升职加薪后结果为：{employee_dict}")


